package com.moody.hibernate.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.moody.hibernate.domain.AssociateAccount;

/**
 * A data access object (DAO) providing persistence and search support for
 * AssociateAccount entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.moody.hibernate.domain.AssociateAccount
 * @author MyEclipse Persistence Tools
 */

public class AssociateAccountDAO extends HibernateDaoSupport {
	private static final Logger log = LoggerFactory
			.getLogger(AssociateAccountDAO.class);
	// property constants
	public static final String CUST_ID = "custId";
	public static final String BANK_NAME = "bankName";
	public static final String ACCOUNT_TYPE = "accountType";
	public static final String ACCOUNT_NO = "accountNo";
	public static final String BEGIN_DATE = "beginDate";
	public static final String CURRENCY = "currency";
	public static final String DEPOSIT_BALANCE = "depositBalance";
	public static final String MONTH_BALANCE = "monthBalance";
	public static final String INPUT_USER_ID = "inputUserId";
	public static final String INPUT_ORG_ID = "inputOrgId";
	public static final String INPUT_DATE = "inputDate";
	public static final String UPDATE_USER_ID = "updateUserId";
	public static final String UPDATE_ORG_ID = "updateOrgId";
	public static final String UPDATE_DATE = "updateDate";

	protected void initDao() {
		// do nothing
	}

	public void save(AssociateAccount transientInstance) {
		log.debug("saving AssociateAccount instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(AssociateAccount persistentInstance) {
		log.debug("deleting AssociateAccount instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public AssociateAccount findById(java.lang.String id) {
		log.debug("getting AssociateAccount instance with id: " + id);
		try {
			AssociateAccount instance = (AssociateAccount) getHibernateTemplate()
					.get("com.moody.hibernate.domain.AssociateAccount", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(AssociateAccount instance) {
		log.debug("finding AssociateAccount instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding AssociateAccount instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from AssociateAccount as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCustId(Object custId) {
		return findByProperty(CUST_ID, custId);
	}

	public List findByBankName(Object bankName) {
		return findByProperty(BANK_NAME, bankName);
	}

	public List findByAccountType(Object accountType) {
		return findByProperty(ACCOUNT_TYPE, accountType);
	}

	public List findByAccountNo(Object accountNo) {
		return findByProperty(ACCOUNT_NO, accountNo);
	}

	public List findByBeginDate(Object beginDate) {
		return findByProperty(BEGIN_DATE, beginDate);
	}

	public List findByCurrency(Object currency) {
		return findByProperty(CURRENCY, currency);
	}

	public List findByDepositBalance(Object depositBalance) {
		return findByProperty(DEPOSIT_BALANCE, depositBalance);
	}

	public List findByMonthBalance(Object monthBalance) {
		return findByProperty(MONTH_BALANCE, monthBalance);
	}

	public List findByInputUserId(Object inputUserId) {
		return findByProperty(INPUT_USER_ID, inputUserId);
	}

	public List findByInputOrgId(Object inputOrgId) {
		return findByProperty(INPUT_ORG_ID, inputOrgId);
	}

	public List findByInputDate(Object inputDate) {
		return findByProperty(INPUT_DATE, inputDate);
	}

	public List findByUpdateUserId(Object updateUserId) {
		return findByProperty(UPDATE_USER_ID, updateUserId);
	}

	public List findByUpdateOrgId(Object updateOrgId) {
		return findByProperty(UPDATE_ORG_ID, updateOrgId);
	}

	public List findByUpdateDate(Object updateDate) {
		return findByProperty(UPDATE_DATE, updateDate);
	}

	public List findAll() {
		log.debug("finding all AssociateAccount instances");
		try {
			String queryString = "from AssociateAccount";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public AssociateAccount merge(AssociateAccount detachedInstance) {
		log.debug("merging AssociateAccount instance");
		try {
			AssociateAccount result = (AssociateAccount) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(AssociateAccount instance) {
		log.debug("attaching dirty AssociateAccount instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(AssociateAccount instance) {
		log.debug("attaching clean AssociateAccount instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static AssociateAccountDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (AssociateAccountDAO) ctx.getBean("AssociateAccountDAO");
	}

	public void update(AssociateAccount associateAccount) {
		log.debug("attaching clean AssociateAccount instance");
		try {
			getHibernateTemplate().update(associateAccount);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}